/*
 * @Description: 消息提示弹窗
 */

import {
  ElMessageBox,
  ElMessage,
  ElNotification,
  ElLoading,
} from "element-plus";

let loadingInstance;

const duration = 3000;

/**
 * @description: 顶部提示弹窗 - 可自动消失
 * @param content 内容
 * @param type 类型
 * @param isShowClose 是否有关闭按钮
 */
export const msgPop = (content, type, isShowClose = false) => {
  ElMessage({
    showClose: isShowClose,
    message: content,
    type: type,
    duration: isShowClose ? 0 : duration,
  });
};

// 消息提示
export const msgInfo = (content) => {
  msgPop(content, "info", false);
};
// 错误消息
export const msgError = (content) => {
  msgPop(content, "error", false);
};
// 成功消息
export const msgSuccess = (content) => {
  msgPop(content, "success", false);
};
// 警告消息
export const msgWarning = (content) => {
  msgPop(content, "warning", false);
};

/**
 * @description: 上下通知弹窗 - 可自动消失
 * @param content 内容
 * @param title 标题
 * @param type 类型
 * @param isShowClose 是否有关闭按钮
 */
export const notificationPop = (
  content,
  title = "系统提示",
  type = "warning",
  isShowClose = true
) => {
  ElNotification({
    title,
    message: content,
    type: type,
    showClose: isShowClose,
    duration: isShowClose ? 0 : duration,
  });
};

/**
 * @description: 中间弹窗 - 确认/取消按钮
 * @param content 内容
 * @param title 标题
 * @param type 类型
 * @param confirmButtonText 确认按钮文本
 * @param cancelButtonText 取消按钮文本
 */
export const messageBoxPop = (
  content,
  title = "系统提示",
  type = "warning",
  confirmButtonText = "确定",
  cancelButtonText = "取消"
) => {
  return ElMessageBox.confirm(content, title, {
    confirmButtonText,
    cancelButtonText,
    type,
  });
};
// 弹窗阻断式提示
export const popBox = (content, title) => {
  return ElMessageBox.alert(content, title, {
    confirmButtonText: "确定",
  });
};
// 打开遮罩层
export const loading = (content = "加载中") => {
  loadingInstance = ElLoading.service({
    lock: true,
    text: content,
    spinner: "el-icon-loading",
    background: "rgba(0, 0, 0, 0.7)",
  });
};
// 关闭遮罩层
export const closeLoading = () => {
  loadingInstance.close();
};
